class_name StatusView
extends Control

const STATUS_TOOLTIP_SCENE = preload("uid://b8aet3kjbnc3u")


@onready var status_tooltips: VBoxContainer = %StatusTooltips

func _ready() -> void:
	Events.status_tooltip_request.connect(show_view)

func _input(event: InputEvent) -> void:
	if event.is_action_pressed("ui_cancel") and visible:
		hide_view()

func _on_back_button_pressed() -> void:
	hide_view()

func _on_gui_input(event: InputEvent) -> void:
	if event.is_action_pressed("left_mouse") and visible:
		hide_view()

func hide_view() -> void:
	for child in status_tooltips.get_children():
		child.queue_free()
	hide()

func show_view(statuses: Array[Status]) -> void:
	for status in statuses:
		var new_status_tooltip : StatusTooltip = STATUS_TOOLTIP_SCENE.instantiate()
		status_tooltips.add_child(new_status_tooltip)
		new_status_tooltip.status = status
	show()
